//
//  LCOrderDetailCell.m
//  ProjectforHDX
//
//  Created by wusiping on 2016/11/10.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "LCOrderDetailCell.h"

#define SEPOFFET 6   //cell底部与最后一个label的距离
#define GAP 16 //左右边距
#define LABHEIGHT 20
#define TOPMARGIN 5


@implementation LCOrderDetailCell

- (void)setDataDict:(NSMutableDictionary *)dataDict{
    
    if ( !dataDict ) {
        return;
    }
    if (_dataDict != dataDict) {
        _dataDict = dataDict;
        self.cellContentView=[[UIView alloc] init];
        [self.cellContentView setClipsToBounds:YES];
        [self.cellContentView setBackgroundColor:[UtilCheck hexStringToColor:@"ffffff" alpha:1]];
        [self addSubview:self.cellContentView];
        
        
        //序号
        self.indexLab =[[RZCustomLable alloc] init ];
        self.indexLab.textColor = [UIColor whiteColor];
        self.indexLab.backgroundColor = SYSTEM_COLOR;
        self.indexLab.textAlignment = NSTextAlignmentCenter;
        self.indexLab.font = CustomFont(14);
        self.indexLab.layer.cornerRadius = LABHEIGHT/2.0;
        self.indexLab.clipsToBounds = YES;
        [self.cellContentView addSubview:self.indexLab];
        
        //板件信息，故障件信息
        self.titleLab =[[RZCustomLable alloc] init ];
        self.titleLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.titleLab.textAlignment = NSTextAlignmentLeft;
        self.titleLab.font = CustomFont(14);
        [self.cellContentView addSubview:self.titleLab];
        
        //板件数量
        self.repairNumLab = [[RZCustomLable alloc] init ];
        self.repairNumLab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.repairNumLab.textAlignment = NSTextAlignmentLeft;
        self.repairNumLab.font = CustomFont(14);
        [self.cellContentView addSubview:self.repairNumLab];
        
        self.left1Lab =[[RZCustomLable alloc] init ];
        self.left1Lab.font = CustomFont(13);
        self.left1Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.left1Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.left1Lab];
        
        
        self.left1Lab =[[RZCustomLable alloc] init ];
        self.left1Lab.font = CustomFont(13);
        self.left1Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.left1Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.left1Lab];
        
        self.right1Lab =[[RZCustomLable alloc] init ];
        self.right1Lab.font = CustomFont(13);
        self.right1Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.right1Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.right1Lab];
        
        self.left2Lab =[[RZCustomLable alloc] init ];
        self.left2Lab.font = CustomFont(13);
        self.left2Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.left2Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.left2Lab];
        
        self.right2Lab =[[RZCustomLable alloc] init ];
        self.right2Lab.font = CustomFont(13);
        self.right2Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.right2Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.right2Lab];
        
        
        self.left3Lab =[[RZCustomLable alloc] init ];
        self.left3Lab.font = CustomFont(13);
        self.left3Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.left3Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.left3Lab];
        
        self.right3Lab =[[RZCustomLable alloc] init ];
        self.right3Lab.font = CustomFont(13);
        self.right3Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.right3Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.right3Lab];
        
        self.left4Lab =[[RZCustomLable alloc] init ];
        self.left4Lab.font = CustomFont(13);
        self.left4Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.left4Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.left4Lab];
        
        
        self.left4Lab =[[RZCustomLable alloc] init ];
        self.left4Lab.font = CustomFont(13);
        self.left4Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.left4Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.left4Lab];
        
        self.right4Lab =[[RZCustomLable alloc] init ];
        self.right4Lab.font = CustomFont(13);
        self.right4Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.right4Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.right4Lab];
        
        
        self.left5Lab =[[RZCustomLable alloc] init ];
        self.left5Lab.font = CustomFont(13);
        self.left5Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.left5Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.left5Lab];
        
        self.left6Lab =[[RZCustomLable alloc] init ];
        self.left6Lab.font = CustomFont(13);
        self.left6Lab.textColor = [UtilCheck hexStringToColor:@"333333" alpha:1];
        self.left6Lab.textAlignment = NSTextAlignmentLeft;
        [self.cellContentView addSubview:self.left6Lab];
        
        
        //分隔线
        self.separateLab =[[RZCustomLable alloc] init ];
        self.separateLab.font = CustomFont(13);
        self.separateLab.textColor = [UIColor grayColor];
        self.separateLab.textAlignment = NSTextAlignmentLeft;
        self.separateLab.backgroundColor = [UtilCheck hexStringToColor:@"e1e1e1" alpha:1];
        [self.cellContentView addSubview:self.separateLab];
        
        self.repairNumLab.text = @"";

    }
 
    
    
    
    
}


- (CGFloat)getHeightWithDict:(NSMutableDictionary *)dataDict{
    CGFloat height = 0;
    
    [self setUpCellDataAndView];
    
    if ([self.type isEqualToString:@"3"]) {
        
        height = self.left6Lab.bottom + SEPOFFET;
        
        
    }
    else if ([self.type isEqualToString:@"6"]||[self.type isEqualToString:@"5"] ){
        
        NSLog(@"右3的位置是%f",self.right3Lab.bottom);
        NSLog(@"左3的位置是%f",self.left3Lab.bottom);
        
        
        height = self.right3Lab.bottom + SEPOFFET;
        
        
    }
    
    else if ([self.type isEqualToString:@"4"]){
        
        height = self.right4Lab.bottom + SEPOFFET;
        
        
    }
    else if ([self.type isEqualToString:@"7"] || [self.type isEqualToString:@"9"] || [self.type isEqualToString:@"11"]){
        
        height = self.right2Lab.bottom + SEPOFFET;
        
        
        
    }
    else if ([self.type isEqualToString:@"8"]){
        NSString *remark = [dataDict objectForKey:@"localStoreRemark"];
        CGSize titleSize = [remark boundingRectWithSize:CGSizeMake(self.width - GAP * 2, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]} context:nil].size;

        height = self.left4Lab.frame.origin.y + self.left4Lab.size.height + SEPOFFET + titleSize.height;
        
        
    }
    
    else if ([self.type isEqualToString:@"10"]){
        
        height = self.left3Lab.bottom + SEPOFFET;
        
        
    }
    
    

    return height;
    
}

- (void)layoutSubviews {
    
    [self setUpCellDataAndView];
}

- (void)setUpCellDataAndView{
    [self.cellContentView setFrame:CGRectMake(0, 0, self.width, self.height)];

    
    CGFloat with = self.width /2;
    CGFloat labWith = with - GAP;
    
    //板件数量
    [self.repairNumLab setFrame:CGRectMake(GAP, TOPMARGIN, self.width, LABHEIGHT)];

    [self.repairNumLab sizeToFit];
    if(self.repairNumLab.height<LABHEIGHT){
        self.repairNumLab.height=LABHEIGHT;
    }
    
    CGFloat beginHeight = self.repairNumLab.bottom + TOPMARGIN;
    if (!_needNum) {
        self.repairNumLab.text = @"";
        [self.repairNumLab sizeToFit];
        self.repairNumLab.hidden = YES;
        beginHeight = GAP;
    }
    
    //序号
    [self.indexLab setFrame:CGRectMake(GAP, beginHeight, LABHEIGHT, LABHEIGHT)];
    [self.indexLab sizeToFit];
    if(self.indexLab.height<LABHEIGHT){
        self.indexLab.height=LABHEIGHT;
        self.indexLab.width=LABHEIGHT;
    }
    
    
    //标题
    [self.titleLab setFrame:CGRectMake(self.indexLab.right + GAP/2, beginHeight, self.width, LABHEIGHT)];
    self.titleLab.text = @"板件信息";
    [self.titleLab sizeToFit];
    if(self.titleLab.height<LABHEIGHT){
        self.titleLab.height=LABHEIGHT;
    }
  
    if ([self.type isEqualToString:@"3"]) {//本地返修订单
        
        self.titleLab.text = [UtilCheck language:@"Order.FaultyUnitInfo"];
        [self.titleLab setWidth:with];
        [self.titleLab sizeToFit];

//        self.left1Lab.text =  [NSString stringWithFormat:@"客户:%@",[_dataDict objectForKey:@"customer"]];


        self.right1Lab.text = [NSString stringWithFormat:@"RMA:%@",[_dataDict objectForKey:@"rma"]];
        
        
        self.left2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[_dataDict objectForKey:@"plateName"]];
        
        self.right2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[_dataDict objectForKey:@"plateCode"]];
      
        
        self.left3Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[_dataDict objectForKey:@"plateVersion"]];

        
        self.right3Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[_dataDict objectForKey:@"plateSN"]];
       
        
        
        self.left4Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.containNo"],[_dataDict objectForKey:@"location"]];
        
        
        self.right4Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.goodWeight"],[_dataDict objectForKey:@"attribution"]];
       

        self.left5Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.spm wh remark"],[_dataDict objectForKey:@"localStoreRemark"]];
        ;
        
        
        
        self.left6Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.faulty gr time"],[_dataDict objectForKey:@"inStoreTime"]];
        ;
        
        
        
    }
    else if ([self.type isEqualToString:@"6"]||[self.type isEqualToString:@"5"]){//调货订单 ，借用订单
        self.left1Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[_dataDict objectForKey:@"plateName"]];
        self.right1Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[_dataDict objectForKey:@"plateCode"]];
        
        
        self.left2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[_dataDict objectForKey:@"plateVersion"]];
        self.right2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[_dataDict objectForKey:@"plateSN"]];
        
        self.left3Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.containNo"],[_dataDict objectForKey:@"location"]];
        self.right3Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.goodWeight"],[_dataDict objectForKey:@"attribution"]];
        
        self.left4Lab.text = @"";
        self.right4Lab.text = @"";
        
        self.left5Lab.text = @"";
        self.left6Lab.text = @"";
        
        
    }
    
    else if ([self.type isEqualToString:@"4"]){//测试订单 LC测试订单
        self.left1Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[_dataDict objectForKey:@"plateName"]];
        self.right1Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[_dataDict objectForKey:@"plateCode"]];
        
        
        self.left2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[_dataDict objectForKey:@"plateVersion"]];
        self.right2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[_dataDict objectForKey:@"plateSN"]];
        
        self.right3Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.containNo"],[_dataDict objectForKey:@"location"]];
        self.left3Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.goodWeight"],[_dataDict objectForKey:@"attribution"]];
        
        self.left4Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.type"],[_dataDict objectForKey:@"plateType"]];
        self.right4Lab.text = @"";
        
        self.left5Lab.text = @"";
        self.left6Lab.text = @"";
        
        
    }
    
    else if ([self.type isEqualToString:@"7"] || [self.type isEqualToString:@"9"] || [self.type isEqualToString:@"11"]){//备件替换发货 备件采购订单 LC报废订单
        self.left1Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[_dataDict objectForKey:@"plateName"]];
        self.right1Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[_dataDict objectForKey:@"plateCode"]];
        
        
        self.left2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[_dataDict objectForKey:@"plateVersion"]];
        self.right2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[_dataDict objectForKey:@"plateSN"]];
        
        self.right3Lab.text=@"";
        self.left3Lab.text=@"";
        
        self.left4Lab.text = @"";
        self.right4Lab.text = @"";
        
        self.left5Lab.text = @"";
        self.left6Lab.text = @"";
        
        
    }
    
    else if ([self.type isEqualToString:@"8"]){//故障件送修订单
        
        self.titleLab.text = [UtilCheck language:@"Order.FaultyUnitInfo"];
        [self.titleLab setWidth:with];
        [self.titleLab sizeToFit];
        
        
        self.left1Lab.text = [NSString stringWithFormat:@"RMA:%@",[_dataDict objectForKey:@"rma"]];
        
        self.right1Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[_dataDict objectForKey:@"plateName"]];
        
        
        self.left2Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[_dataDict objectForKey:@"plateCode"]];
        self.right2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[_dataDict objectForKey:@"plateVersion"]];
        
        
        self.left3Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[_dataDict objectForKey:@"plateSN"]];
        self.right3Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.goodWeight"],[_dataDict objectForKey:@"attribution"]];
        
        
        self.left4Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"seeting.troubleDescribe"],[_dataDict objectForKey:@"localStoreRemark"]];
        
        //在代码中修改xib约束.xib中约束宽度太小。
        //        self.Left4With.constant = self.width - GAP * 2;
        [self.left4Lab sizeToFit];
        self.right4Lab.text = @"";
        
        self.left5Lab.text = @"";
        self.left6Lab.text = @"";
        
        
    }
    
    else if ([self.type isEqualToString:@"10"]){//返修订单
        self.left1Lab.text = [NSString stringWithFormat:@"RMA:%@",[_dataDict objectForKey:@"rma"]];
        self.right1Lab.text = [NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateName"],[_dataDict objectForKey:@"plateName"]];
        
        
        self.left2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateNO"],[_dataDict objectForKey:@"plateCode"]];
        self.right2Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateCode"],[_dataDict objectForKey:@"plateVersion"]];
        
        self.left3Lab.text=[NSString stringWithFormat:@"%@:%@",[THMangerTool language:@"setting.plateSerial"],[_dataDict objectForKey:@"plateSN"]];
        self.right3Lab.text= @"";
        
        self.left4Lab.text = @"";
        self.right4Lab.text = @"";
        
        self.left5Lab.text = @"";
        self.left6Lab.text = @"";
    }
    
    
    [self.left1Lab setFrame:CGRectMake(GAP, self.indexLab.bottom + TOPMARGIN, labWith, LABHEIGHT)];
    [self.left1Lab sizeToFit];
    if(self.left1Lab.height<LABHEIGHT){
        self.left1Lab.height=LABHEIGHT;
    }
    
    
    [self.right1Lab setFrame:CGRectMake(with, self.indexLab.bottom + TOPMARGIN, labWith, LABHEIGHT)];
    [self.right1Lab sizeToFit];
    if(self.right1Lab.height<LABHEIGHT){
        self.right1Lab.height=LABHEIGHT;
    }
    
    
    [self.left2Lab setFrame:CGRectMake(GAP, TOPMARGIN + self.left1Lab.bottom , labWith, LABHEIGHT)];
    [self.left2Lab sizeToFit];
    if(self.left2Lab.height<LABHEIGHT){
        self.left2Lab.height=LABHEIGHT;
    }
    
    
    [self.right2Lab setFrame:CGRectMake(with, TOPMARGIN + self.right1Lab.bottom, labWith, LABHEIGHT)];
    [self.right2Lab sizeToFit];
    if(self.right2Lab.height<LABHEIGHT){
        self.right2Lab.height=LABHEIGHT;
    }
    
    
    [self.left3Lab setFrame:CGRectMake(GAP, TOPMARGIN + self.left2Lab.bottom, labWith, LABHEIGHT)];
    [self.left3Lab sizeToFit];
    if(self.left3Lab.height<LABHEIGHT){
        self.left3Lab.height=LABHEIGHT;
    }
    
    
    
    [self.right3Lab setFrame:CGRectMake(with, TOPMARGIN + self.right2Lab.bottom, labWith, LABHEIGHT)];
    [self.right3Lab sizeToFit];
    if(self.right3Lab.height<LABHEIGHT){
        self.right3Lab.height=LABHEIGHT;
    }
    
    
    [self.left4Lab setFrame:CGRectMake(GAP, TOPMARGIN + self.left3Lab.bottom, labWith, LABHEIGHT)];
    [self.left4Lab sizeToFit];
    if(self.left4Lab.height<LABHEIGHT){
        self.left4Lab.height=LABHEIGHT;
    }
    
    
    [self.right4Lab setFrame:CGRectMake(with, TOPMARGIN + self.right3Lab.bottom, labWith, LABHEIGHT)];
    if(self.right4Lab.height<LABHEIGHT){
        self.right4Lab.height=LABHEIGHT;
    }
    
    
    [self.left5Lab setFrame:CGRectMake(GAP, TOPMARGIN + self.left4Lab.bottom, labWith*2, LABHEIGHT)];
    
    if(self.left5Lab.height<LABHEIGHT){
        self.left5Lab.height=LABHEIGHT;
    }
    
    [self.left6Lab setFrame:CGRectMake(GAP, TOPMARGIN + self.left5Lab.bottom, labWith*2, LABHEIGHT)];
    if(self.left6Lab.height<LABHEIGHT){
        self.left6Lab.height=LABHEIGHT;
    }

    
    [self.separateLab setFrame:CGRectMake(GAP, self.contentView.bottom - 0.5, self.width - GAP * 2, 0.5)];

    
    
}

- (void)awakeFromNib {
    
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}
@end
